//
//  WebViewController.m
//  Patient
//
//  Created by Alex Xu on 10/5/13.
//  Copyright (c) 2013 GePingTech. All rights reserved.
//

#import "WebViewController.h"
#import "UIWindow+YzdHUD.h"
@interface WebViewController() <UIWebViewDelegate>

@end

@implementation WebViewController
{
    UIWebView *web;
    NSString *urlString;
}

@synthesize urlString;

- (void)viewDidLoad
{
//    hasCustomBackButton = YES;
    [super viewDidLoad];
    //提示网络状态
    [self showNetStatus];
    CGSize size = [UIScreen mainScreen].bounds.size;
    //
    web = [[UIWebView alloc] initWithFrame:AutoRectMake(0, 0, size.width, size.height, WTFAutoLayoutTypePic)];
    web.delegate = self;
    web.scalesPageToFit = YES;
    [self.view addSubview:web];
    
    if ([urlString length] > 0) {
        NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.urlString]];
//                NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"www.baidu.com"]];
        [web loadRequest:request];
    }
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [self.view.window showHUDWithText:@"加载中" Type:ShowLoading Enabled:YES];
//    [self startLoading];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self.view.window showHUDWithText:@"加载成功" Type:ShowPhotoYes Enabled:YES];
//    [self stopLoading];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    [self.view.window showHUDWithText:@"加载失败" Type:ShowPhotoNo Enabled:YES];
//    [self stopLoading];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    web.delegate = nil;
    [self.view.window showHUDWithText:nil Type:ShowDismiss Enabled:YES];
    web = nil;
}

@end
